package com.hnl.action.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.aware.HNLTalentAware;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.UserDAO;
import com.hnl.to.User;
import com.hnl.to.wrapper.UserWrapper;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
public class LoadConsultant extends HttpServlet implements HNLTalentAware {
	public static final Logger LOG = LoggerFactory.getLogger(LoadConsultant.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try{
			User user = new User();
			PrintWriter writer = resp.getWriter();
			String userID = req.getParameter("userID");
			
			if(userID!=null && userID.length()!=0){
				UserDAO userDAO = HNLDAOFactory.getDAOFactory(
						HNLDAOFactory.HNLDAOFACTORY).getUserDAO();
				user = userDAO.loadUserByUserID(Integer.valueOf(userID));
				
				UserWrapper newUserWrapper = new UserWrapper(user);
				newUserWrapper.getUserIDText();
				newUserWrapper.getModifiedUserIDText();
				newUserWrapper.getRoleNameID();
				newUserWrapper.getRoleNameText();
				
				writer.println(JSONResponseUtil.getJSONObjectString(newUserWrapper));
			}
//			else{
//				writer.println(JSONResponseUtil.getJSONObjectString(user));
//			}
		}catch (DAOException e) {
			LOG.error("error laoding Talent", e);
		}
		
	}
	
	
}
